{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Capital BikeShare"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、导入必要的工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "import seaborn as sns\n",
    "\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、数据探索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>dteday</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2011-01-01</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.344167</td>\n",
       "      <td>0.363625</td>\n",
       "      <td>0.805833</td>\n",
       "      <td>0.160446</td>\n",
       "      <td>331</td>\n",
       "      <td>654</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2011-01-02</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.363478</td>\n",
       "      <td>0.353739</td>\n",
       "      <td>0.696087</td>\n",
       "      <td>0.248539</td>\n",
       "      <td>131</td>\n",
       "      <td>670</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2011-01-03</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.196364</td>\n",
       "      <td>0.189405</td>\n",
       "      <td>0.437273</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>120</td>\n",
       "      <td>1229</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2011-01-04</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>0.212122</td>\n",
       "      <td>0.590435</td>\n",
       "      <td>0.160296</td>\n",
       "      <td>108</td>\n",
       "      <td>1454</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>2011-01-05</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.226957</td>\n",
       "      <td>0.229270</td>\n",
       "      <td>0.436957</td>\n",
       "      <td>0.186900</td>\n",
       "      <td>82</td>\n",
       "      <td>1518</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant      dteday  season  yr  mnth  holiday  weekday  workingday  \\\n",
       "0        1  2011-01-01       1   0     1        0        6           0   \n",
       "1        2  2011-01-02       1   0     1        0        0           0   \n",
       "2        3  2011-01-03       1   0     1        0        1           1   \n",
       "3        4  2011-01-04       1   0     1        0        2           1   \n",
       "4        5  2011-01-05       1   0     1        0        3           1   \n",
       "\n",
       "   weathersit      temp     atemp       hum  windspeed  casual  registered  \\\n",
       "0           2  0.344167  0.363625  0.805833   0.160446     331         654   \n",
       "1           2  0.363478  0.353739  0.696087   0.248539     131         670   \n",
       "2           1  0.196364  0.189405  0.437273   0.248309     120        1229   \n",
       "3           1  0.200000  0.212122  0.590435   0.160296     108        1454   \n",
       "4           1  0.226957  0.229270  0.436957   0.186900      82        1518   \n",
       "\n",
       "    cnt  \n",
       "0   985  \n",
       "1   801  \n",
       "2  1349  \n",
       "3  1562  \n",
       "4  1600  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv(\"day.csv\")\n",
    "data_copy = pd.read_csv(\"day.csv\")\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  2.2 数据基本信息\n",
    "样本数目、特征维数\n",
    "每个特征的类型、空值样本的数目、数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "del data['dteday']\n",
    "del data['instant']\n",
    "del data['atemp']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['season', 'mnth', 'holiday', 'weekday', 'workingday', 'weathersit',\n",
       "       'temp', 'hum', 'windspeed'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = data.drop(['yr','casual','registered','cnt'], axis = 1)\n",
    "\n",
    "#用于后续显示权重系数对应的特征\n",
    "columns = X.columns\n",
    "columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/lihuixiang/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:444: DataConversionWarning: Data with input dtype int64 was converted to float64 by the scale function.\n",
      "  warnings.warn(msg, DataConversionWarning)\n"
     ]
    }
   ],
   "source": [
    "# 按年份分离train & test data\n",
    "data_train=data[data.yr<1]\n",
    "data_test=data[data.yr>0]\n",
    "\n",
    "# y 值输入 + 两年的数值范围不易，做均值补偿\n",
    "# from sklearn.preprocessing import Normalizer\n",
    "y_train = data_train['registered'].values\n",
    "y_test = data_test['registered'].values\n",
    "# y_train\n",
    "# y_train = Normalizer().fit_transform(y_train.reshape(-1,1)) \n",
    "# y_test = Normalizer().transform(y_test.reshape(-1,1))\n",
    "# from sklearn.preprocessing import Normalizer\n",
    "# y_train=Normalizer().fit_transform(y_train.reshape(-1,1))\n",
    "# y_test=Normalizer().fit_transform(y_test.reshape(-1,1))\n",
    "\n",
    "from sklearn import preprocessing\n",
    "y_train = preprocessing.scale(y_train.reshape(-1, 1))\n",
    "y_test = preprocessing.scale(y_test.reshape(-1, 1))\n",
    "\n",
    "# define value features\n",
    "columns_num = ['mnth','holiday','weekday','workingday','season','weathersit','cnt','yr','registered','casual']\n",
    "columns_onehot=['cnt','yr','registered','casual','temp','hum','windspeed']\n",
    "# seperate x into to catagories, one with value features, another contains classfied features\n",
    "X_train_onehot=data_train.drop(columns_onehot,axis=1)\n",
    "X_train_num=data_train.drop(columns_num,axis=1)\n",
    "X_test_onehot=data_test.drop(columns_onehot,axis=1)\n",
    "X_test_num=data_test.drop(columns_num,axis=1)\n",
    "\n",
    "# onehotencoder the x which contains classified features\n",
    "from sklearn.preprocessing import OneHotEncoder\n",
    "X_train_onehot=OneHotEncoder(sparse=False).fit_transform(X_train_onehot)\n",
    "X_test_onehot=OneHotEncoder(sparse=False).fit_transform(X_test_onehot)\n",
    "# X_train_onehot=OneHotEncoder().fit_transform(X_train_onehot)\n",
    "# X_test_onehot=OneHotEncoder().fit_transform(X_test_onehot)\n",
    "\n",
    "# X_train_onehot=pd.DataFrame(OneHotEncoder().fit_transform(X_train_onehot).toarray())\n",
    "# X_test_onehot=pd.DataFrame(OneHotEncoder().fit_transform(X_test_onehot).toarray())\n",
    "\n",
    "\n",
    "#Normalize the x which contains value features\n",
    "from sklearn.preprocessing import Normalizer\n",
    "X_train_num=Normalizer().fit_transform(X_train_num)\n",
    "X_test_num=Normalizer().fit_transform(X_test_num)\n",
    "\n",
    "# from sklearn import preprocessing\n",
    "# enc = preprocessing.OneHotEncoder()\n",
    "# #onehot = pd.DataFrame(enc.fit_transform(data[['season','mnth','weekday','weathersit']]).toarray())\n",
    "# data22=data[['season','mnth','weekday','weathersit']]\n",
    "# onehot = pd.DataFrame(enc.fit_transform(X_train_onehot).toarray())\n",
    "\n",
    "# onehot\n",
    "\n",
    "# # data_temp = data.drop(['season','mnth','weekday','weathersit'], axis = 1)\n",
    "# data_new = pd.concat([X_train_num, X_train_onehot],axis=1 )  #与独热编码的数据合并\n",
    "\n",
    "# data22=data[['season','mnth','weekday','weathersit']]\n",
    "# data11=data_train.drop(columns_onehot,axis=1)\n",
    "#data22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(365, 3)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# verify shape of two Xs\n",
    "X_train_num.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.,  0.,  0., ...,  0.,  1.,  0.],\n",
       "       [ 1.,  0.,  0., ...,  0.,  1.,  0.],\n",
       "       [ 1.,  0.,  0., ...,  1.,  0.,  0.],\n",
       "       ..., \n",
       "       [ 1.,  0.,  0., ...,  1.,  0.,  0.],\n",
       "       [ 1.,  0.,  0., ...,  1.,  0.,  0.],\n",
       "       [ 1.,  0.,  0., ...,  1.,  0.,  0.]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# verify shape of two Xs\n",
    "X_train_onehot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.        ,  0.        ,  0.        , ...,  0.38634844,\n",
       "         0.90459666,  0.18011042],\n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.44129317,\n",
       "         0.84510875,  0.30174746],\n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.36374692,\n",
       "         0.8100095 ,  0.45997043],\n",
       "       ..., \n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.38993074,\n",
       "         0.901553  ,  0.18749989],\n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.43198526,\n",
       "         0.8824507 ,  0.18619746],\n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.53116203,\n",
       "         0.79782221,  0.28521328]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# merge two Xs\n",
    "X_train=np.hstack((X_train_onehot,X_train_num))\n",
    "X_test=np.hstack((X_test_onehot,X_test_num))\n",
    "X_train\n",
    "\n",
    "\n",
    "# from scipy.sparse import hstack \n",
    "# X_train=hstack((X_train_num,X_train_onehot))\n",
    "# X_test=hstack((X_test_num,X_test_onehot))\n",
    "\n",
    "# X_train=pd.concat([X_train_onehot,X_train_num],axis=1)\n",
    "# X_train"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、确定模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1 尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 线性回归\n",
    "#class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 使用默认配置初始化\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 预测\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "# columns=X_train.columns\n",
    "\n",
    "# # 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "# fs = pd.DataFrame({\"columns\":list(columns), \"coef\":list((lr.coef_.T))})\n",
    "# fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.1.1 模型评价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.689213354972\n",
      "The r2 score of LinearRegression on train is 0.858172267968\n"
     ]
    }
   ],
   "source": [
    "# 使用r2_score评价模型在测试集和训练集上的性能，并输出评估结果\n",
    "#测试集\n",
    "print ('The r2 score of LinearRegression on test is', r2_score(y_test, y_test_pred_lr))\n",
    "#训练集\n",
    "print ('The r2 score of LinearRegression on train is', r2_score(y_train, y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAekAAAFsCAYAAADos0H8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHFpJREFUeJzt3XuUXGWZ7/HvQ2iJQyAQ6EBIjAEE5ZoONpgMAwajgIIE\nz6jI4boIBFFm4XUUPA4to0ddIC45MiyjIiAot5GBGfUMnAgT4ShMwkRuQRORHBNiCEEuQZBcnvNH\n7cQm6U5Xuqu733R9P2vVqqq9d+391NvV/ev33bvfjsxEkiSVZ5vBLkCSJHXNkJYkqVCGtCRJhTKk\nJUkqlCEtSVKhDGlJkgplSKvpRcSjETF1sOsYTBHxvoj4fUSsiohJA3jcVRGxVzfrzoyIext0nCcj\n4p2N2Jc0kAxpDWld/XDe+Id/Zh6Qmff0sJ8JEZERsW0/lTrYLgPOz8wRmflfG6+s3vtLVagujYjL\nI2JYXw9aHe+Jvu5HGqoMaakABYT/G4FHe9hmYmaOAN4OnASc1e9VSU3OkFbT69zbjojDImJuRLwQ\nEcsj4vJqsznV/XNVb3JKRGwTEf8jIhZHxNMRcV1EjOy039OrdSsj4vMbHacjIm6NiOsj4gXgzOrY\nv4iI5yJiWUR8MyJe12l/GREfiYiFEfFiRPxjROxdveaFiLi58/Ybvccua42I7SJiFTAM+FVE/Lan\n9srMRcB9QFun/Y+MiO9WdS+NiC+u72lHxJsi4j8i4vmIeCYibtroPb2perxLRNxRvZcHgL07bbfJ\nSEZE3BMRZ1eP946In1Vt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Nf1nrwf1tM+/Aj/MzD9HxIepjUy8o98rGzoG9DO4VYV0\nZr6zAft4qrp/OiJuozY81FQh3YB2bPopYTfXhhGxPCLGZOayahjs6W72sf6z+ERE3ANMApo5pOv5\nXK3fZklEbAuMZPNDk82mxzbMzJWdnn4bz+tvqQH9+ddUw90RsX1E7LD+MXA0tQultGWcEnbz7gDO\nqB6fAWwyOhERO0fEdtXjXYHDgccGrMIy1fO56ty27wd+ls7I1FmPbbjR+dMTgAUDWN9QcAdwenWV\n92Tg+fWnt/pFZg6JG/A+ar/h/BlYDvx7tXwP4CfV472AX1W3R6kN7w567SXd6mnH6vl7gN9Q6/nZ\njq9tw12oXdW9sLofVS1vB75TPf5r4OHqs/gwMGOw6y7h1tXnCrgEOKF6PBy4BVgEPADsNdg1l3ar\now2/XP38+xVwN/CWwa65pBvwQ2AZsLr6WTgD+DDw4Wp9ULuC/rfV9257f9bjtKCSJBWqqYa7JUna\nmhjSkiQVypCWJKlQhrQkSYUypCVJKpQhLUlSoQxpSZIK9f8BLPmxtXe+KIIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a16540a20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - y_train_pred_lr,bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "残差分布和高斯分布比较匹配，但还是左skew，可能是由于数据集中有16个数据的y值为最大值，有噪声（预测残差超过2.5）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQ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
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, y_train_pred_lr)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True ')\n",
    "plt.ylabel('Predicted ')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在y的真值大的部分预测效果不好"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/lihuixiang/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:547: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([-0.59124478, -0.21024766,  0.11160377,  0.45737536, -0.53130522,\n",
       "       -0.43452676, -0.46787755, -0.07813284,  0.60830472,  0.57530528,\n",
       "       -0.03743059,  0.09986579,  0.33061028,  0.01554837, -0.20527435,\n",
       "       -0.10760044, -0.00945584, -0.22305747, -0.14779786, -0.05468956,\n",
       "        0.04145971,  0.02194682, -0.00440364, -0.04892705, -0.04010175,\n",
       "       -0.41095708,  0.17844377,  0.46305911,  0.23012699, -0.92569941,\n",
       "        1.17744327, -0.59241337, -0.67795555])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性模型，随机梯度下降优化模型参数\n",
    "# 随机梯度下降一般在大数据集上应用，其实本项目不适合用\n",
    "from sklearn.linear_model import SGDRegressor\n",
    "\n",
    "# 使用默认配置初始化线\n",
    "sgdr = SGDRegressor(max_iter=1000)\n",
    "\n",
    "# 训练：参数估计\n",
    "sgdr.fit(X_train, y_train)\n",
    "\n",
    "# 预测\n",
    "#sgdr_y_predict = sgdr.predict(X_test)\n",
    "\n",
    "sgdr.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of SGDRegressor on test is 0.659777111974\n",
      "The value of default measurement of SGDRegressor on train is 0.854617347756\n"
     ]
    }
   ],
   "source": [
    "# 使用SGDRegressor模型自带的评估模块(评价准则为r2_score)，并输出评估结果\n",
    "print ('The value of default measurement of SGDRegressor on test is', sgdr.score(X_test, y_test))\n",
    "print ('The value of default measurement of SGDRegressor on train is', sgdr.score(X_train, y_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#这里由于样本数不多，SGDRegressor可能不如LinearRegression。 sklearn建议样本数超过10万采用SGDRegressor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 正则化的线性回归（L2正则 --> 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.686558030103\n",
      "The r2 score of RidgeCV on train is 0.858232469719\n"
     ]
    }
   ],
   "source": [
    "#岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None, \n",
    "#                                  store_cv_values=False)\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "#设置超参数（正则参数）范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "#n_alphas = 20\n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)  \n",
    "\n",
    "#模型训练\n",
    "ridge.fit(X_train, y_train)    \n",
    "\n",
    "#预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of RidgeCV on test is', r2_score(y_test, y_test_pred_ridge))\n",
    "print ('The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl0XOWZ5/Hvo837Lu+WLYEdg9kMCIGtkIQAiUkmhiw0\nhkBsT3py0h2m05PpmdAnfchp+uT0dDKTOaenySR0DzYJECcESJvEhARCNsk2FsZ4Iw6yXbJleZE3\nyZv2Z/6oa7uQJZVk69at5fc5R0d1731v3UfXVv1U933rvebuiIiI9CUv6gJERCT9KSxERCQphYWI\niCSlsBARkaQUFiIikpTCQkREklJYiIhIUgoLERFJSmEhIiJJFURdwGApLi720tLSqMsQEckob775\n5mF3n5isXdaERWlpKTU1NVGXISKSUcysrj/tdBlKRESSUliIiEhSCgsREUlKYSEiIkkpLEREJCmF\nhYiIJKWwEBGRpEINCzNbZGY7zKzWzB7po91nzMzNrDxh3d8G++0ws4+GWaeISKZ68a16nqvZS9i3\nyA4tLMwsH3gcuAuYB9xvZvN6aDcK+CtgfcK6ecAS4CpgEfCd4PlERCTQ0dnFt36xgxff2oeZhXqs\nMN9ZVAC17r7L3duAVcDdPbT7B+CbQEvCuruBVe7e6u67gdrg+UREJPDL7QdpaGph2cLS0I8VZlhM\nB/YmLNcH684xs+uBEnf/2UD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NbmND+p0ENIqFSWIic9ylgPnAdcAfwrWAajE8BpcA1wJ8DCxL2\nqQTeTFj+mruXA9cCHzSza3s4zghgo7vfAPwW+HrCtgJ3rwD+OmH9IeDOoP19wD8ntK8Bbh34jyoy\nMFk9kaDIAL2f+MyrncBBM/stcFOw/jl37wIOmNnrCftMBRoTlv8smDK+INg2j/j0DIm6gB8Fj58G\nEieEO/v4TeIBBVAI/IuZzQc6gfcltD9EfMoVkVApLETO6+0mRH3dnOgM8fmeMLMy4G+Am9z9mJmt\nPLsticQ5d1qD752c//38L8Tn47qO+NWAloT2Q4MaREKly1Ai5/0OuM/M8oN+hA8Qn+zvD8RvDJRn\nZpOJ31bzrHeA2cHj0cApoClod1cvx8kjPuMswAPB8/dlDLA/eGfzEPHbpJ71PtJjxmHJcnpnIXLe\ni8T7I94m/tf+f3f3A2b2PHA78RflPxG/O1lTsM/PiYfHq+7+tpm9RXxG0l1AVS/HOQVcZWZvBs9z\nX5K6vgM8b2b3Ep8R9lTCttuCGkRCpVlnRfrBzEZ6/M5oE4i/26gMgmQY8RfwyqCvoz/PddLdRw5S\nXb8D7nb3Y4PxfCK90TsLkf75mZmNBYqAf3D3AwDufsbMvk78Psd7UllQcKns2woKSQW9sxARkaTU\nwS0iIkkpLEREJCmFhYiIJKWwEBGRpBQWIiKSlMJCRESS+v9c7CO/BCKHEAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a1fe2f358>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.01\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(9,)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "# fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T))})\n",
    "# fs.sort_values(by=['coef_lr'],ascending=False)\n",
    "\n",
    "columns.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3 正则化的线性回归（L1正则 --> Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.684415677492\n",
      "The r2 score of LassoCV on train is 0.858074084676\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/lihuixiang/anaconda3/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:1094: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    }
   ],
   "source": [
    "#### Lasso／L1正则\n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#设置超参数搜索范围\n",
    "#alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#生成一个LassoCV实例\n",
    "#lasso = LassoCV(alphas=alphas)  \n",
    "lasso = LassoCV()  \n",
    "\n",
    "#训练（内含CV）\n",
    "lasso.fit(X_train, y_train)  \n",
    "\n",
    "#测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of LassoCV on test is', r2_score(y_test, y_test_pred_lasso))\n",
    "print ('The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VPW9//HXJzshQAJhT0JAcAEEgSAoarWtLVqVqrXW\npS5Vub/b2u3XzVtbafW2Wtve9terVrnWpbcVXKoWLUrdcYcg+75DEiBhy0LWmfn+/pghjZiQgeTM\nmUnez8djHrN9Z87nyyHnPWf7HnPOISIiApDkdwEiIhI/FAoiItJMoSAiIs0UCiIi0kyhICIizRQK\nIiLSTKEgIiLNFAoiItJMoSAiIs1S/C7gWOXm5rrCwkK/yxARSShLlizZ65zr3167hAuFwsJCiouL\n/S5DRCShmNn2aNpp85GIiDRTKIiISDOFgoiINFMoiIhIM4WCiIg08ywUzOwRMys3s1VHaXOumS0z\ns9Vm9pZXtYiISHS8XFN4DJje1ptmlg08AFzinBsDXOFhLSIiEgXPQsE5txDYf5QmVwPPOud2RNqX\ne1WLiEii+/2rG1i+86Dn0/Fzn8KJQI6ZvWlmS8zsOh9rERGJW+9s3MvvX93Ia+u8/+3s5xnNKcAk\n4DNAD+B9M/vAObfhyIZmNhOYCVBQUBDTIkVE/NQQCHLH31cxrF8mXz/3BM+n5+eaQgnwsnPukHNu\nL7AQGN9aQ+fcbOdckXOuqH//dofuEBHpMh56awtb9h7irhljyUhN9nx6fobC34GzzSzFz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eGjE6JvDea8NAjLYWAJyOP/wI82+K9w4+X\nEA4igFTgPjM7DQgCJ7ZoX054eAYRTykUpDtqbbjko70OUAdkAJjZcOD7wGTn3AEze+zwe+1oOaZM\nQ+Q+yL/+Dr9LeIye8YTX4utbtM+I1CDiKW0+ku5oIXClmSVHtvOfAywC3gEuj+xbGMjHhx9fC4yM\nPO4NHAIqI+0uaGM6ScDhfRJXR77/aPoAuyJrKl8lfKnIw04kcUcilQSiNQXpjp4jvL9gOeFf7z90\nzu02s78BnyG88N0AfAhURj7zD8Ih8apzbrmZLSU8QugW4N02pnMIGGNmSyLfc2U7dT0A/M3MrgDe\niHz+sPMiNYh4SqOkirRgZlnOuRoz60d47WFaJDB6EF5QT4vsi4jmu2qcc1mdVNdCYIYLX3NbxDNa\nUxD5uBfNLBtIA+5yzu0GcM7Vmdkswtfv3RHLgiKbuP5LgSCxoDUFERFpph3NIiLSTKEgIiLNFAoi\nItJMoSAiIs0UCiIi0kyhICIizf4/ZUm/fLBzU9sAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a1fe2f160>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.000302728545041\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "           \n",
    "print ('alpha is:', lasso.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "# fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "# fs.sort_values(by=['coef_lr'],ascending=False)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8VPW9//HXJzshQAJhT0JAcAEEgSAoarWtLVqVqrXW\npS5Vub/b2u3XzVtbafW2Wtve9terVrnWpbcVXKoWLUrdcYcg+75DEiBhy0LWmfn+/pghjZiQgeTM\nmUnez8djHrN9Z87nyyHnPWf7HnPOISIiApDkdwEiIhI/FAoiItJMoSAiIs0UCiIi0kyhICIizRQK\nIiLSTKEgIiLNFAoiItJMoSAiIs1S/C7gWOXm5rrCwkK/yxARSShLlizZ65zr3167hAuFwsJCiouL\n/S5DRCShmNn2aNpp85GIiDRTKIiISDOFgoiINFMoiIhIM4WCiIg08ywUzOwRMys3s1VHaXOumS0z\ns9Vm9pZXtYiISHS8XFN4DJje1ptmlg08AFzinBsDXOFhLSIiEgXPQsE5txDYf5QmVwPPOud2RNqX\ne1WLiEii+/2rG1i+86Dn0/Fzn8KJQI6ZvWlmS8zsOh9rERGJW+9s3MvvX93Ia+u8/+3s5xnNKcAk\n4DNAD+B9M/vAObfhyIZmNhOYCVBQUBDTIkVE/NQQCHLH31cxrF8mXz/3BM+n5+eaQgnwsnPukHNu\nL7AQGN9aQ+fcbOdckXOuqH//dofuEBHpMh56awtb9h7irhljyUhN9nx6fobC34GzzSzFzDKBKcBa\nH+sREYkr2/Ye4r43NvGFcYM558TY/CD2bPORmc0BzgVyzawEmAWkAjjnHnTOrTWzl4EVQAh42DnX\n5uGrIiLdiXOOO+atJi05iTsuGh2z6XoWCs65q6Jo82vg117VICKSqJ4uLmHhhgpmXTyagb0zYjZd\nndEsIhJndu6v5ecvrGbqiL5cf0ZhTKetUBARiSPBkON7Ty0nyYzfXDGepCSL6fQVCi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uyJrKl8lfKnIw04kcUcilQSiNQXpjp4jvL9gOeFf7z90\nzu02s78BnyG88N0AfAhURj7zD8Ih8apzbrmZLSU8QugW4N02pnMIGGNmSyLfc2U7dT0A/M3MrgDe\niHz+sPMiNYh4SqOkirRgZlnOuRoz60d47WFaJDB6EF5QT4vsi4jmu2qcc1mdVNdCYIYLX3NbxDNa\nUxD5uBfNLBtIA+5yzu0GcM7Vmdkswtfv3RHLgiKbuP5LgSCxoDUFERFpph3NIiLSTKEgIiLNFAoi\nItJMoSAiIs0UCiIi0kyhICIizf4/ZUm/fLBzU9sAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a203ac1d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.000302728545041\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
